home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_client_info.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  8.8 KB  |  427 lines

  1. unit ntc_client_info;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     StdCtrls,
  36.     ExtCtrls,
  37.     inifiles,
  38.     Buttons,
  39.  
  40.     ntc_client_form,
  41.     ntc_client_network,
  42.     ntc_client_control,
  43.     ntc_client_object;
  44.  
  45. const
  46.     default_refresh_rate=30000;
  47.  
  48. type
  49.     Tscope_info = class(tform)
  50.         info_panel: TPanel;
  51.         coord_box: TGroupBox;
  52.         ra_label: TLabel;
  53.         alt_label: TLabel;
  54.         dec_label: TLabel;
  55.         az_label: TLabel;
  56.         hours_label: TLabel;
  57.         ra_minutes_label: TLabel;
  58.         ra_seconds_label: TLabel;
  59.         degrees_label: TLabel;
  60.         minutes_label: TLabel;
  61.         seconds_label: TLabel;
  62.         refresh_rate_label: TLabel;
  63.         dec_degrees_edit: TEdit;
  64.         alt_degrees_edit: TEdit;
  65.         az_degrees_edit: TEdit;
  66.         ra_hours_edit: TEdit;
  67.         ra_minutes_edit: TEdit;
  68.         ra_seconds_edit: TEdit;
  69.         dec_minutes_edit: TEdit;
  70.         dec_seconds_edit: TEdit;
  71.         az_minutes_edit: TEdit;
  72.         az_seconds_edit: TEdit;
  73.         alt_minutes_edit: TEdit;
  74.         alt_seconds_edit: TEdit;
  75.         info_label: TLabel;
  76.         get_ra_dec_button: TBitBtn;
  77.         get_alt_az_button: TBitBtn;
  78.         get_all_button: TBitBtn;
  79.     controller_timer: TTimer;
  80.     refresh_rate_edit: TEdit;
  81.     msecs_label: TLabel;
  82.     timer_button: TBitBtn;
  83.  
  84.         { form functions }
  85.         procedure formcreate(
  86.             Sender:TObject);
  87.  
  88.         procedure form_close_query(
  89.                     Sender: TObject;
  90.             var CanClose: Boolean);
  91.  
  92.         { information retrieval }
  93.         procedure get_info;
  94.  
  95.         Procedure show_info;
  96.  
  97.         procedure get_ra_dec;
  98.  
  99.         procedure get_az_alt;
  100.  
  101.         { configuration }
  102.         procedure load_settings;
  103.  
  104.         procedure save_settings;
  105.  
  106.         { events }
  107.         procedure FormShow(
  108.             Sender: TObject);
  109.  
  110.         procedure adjust;
  111.  
  112.         procedure check_activate(
  113.             Sender: TObject);
  114.  
  115.         procedure refresh_rate_editChange(
  116.             Sender: TObject);
  117.  
  118.         procedure get_ra_dec_buttonClick(
  119.             Sender: TObject);
  120.  
  121.         procedure get_alt_az_buttonClick(
  122.             Sender: TObject);
  123.  
  124.         procedure get_all_buttonClick(
  125.             Sender: TObject);
  126.  
  127.         procedure timer_buttonClick(
  128.             Sender: TObject);
  129.  
  130.         procedure controller_timerTimer(
  131.             Sender: TObject);
  132.  
  133.     private
  134.         { global information }
  135.     public
  136.         { Public declarations }
  137.         info_string:string;
  138.         { configuration }
  139.         dimensions:dimensions_record;
  140.         refresh_rate:integer;
  141.  
  142.         { events }
  143.         procedure check_visible_and_show_hide(
  144.             sender:tobject);
  145.             
  146.         procedure hide_form;
  147.         procedure show_form;
  148.     end;
  149.  
  150. var
  151.     scope_info: Tscope_info;
  152.  
  153. implementation
  154.  
  155. uses
  156.     ntc_client_focus,
  157.     ntc_client_tracking,
  158.     ntc_client_search;
  159.  
  160. {$R *.dfm}
  161.  
  162.     { --------------
  163.         form functions
  164.         -------------- }
  165.  
  166. procedure Tscope_info.formcreate(
  167.     Sender:TObject);
  168. begin
  169.     controller_timer.enabled:=false;
  170.     load_settings;
  171. end;
  172.  
  173. procedure Tscope_info.form_close_query(
  174.             Sender: TObject;
  175.     var CanClose: Boolean);
  176. begin
  177.     canclose:=false;
  178.     visible:=false;
  179.     with dimensions do
  180.         begin
  181.             form_top:=top;
  182.             form_left:=left;
  183.         end;
  184. end;
  185.  
  186.     { ---------------------
  187.         information retrieval
  188.         --------------------- }
  189.  
  190. Procedure tscope_info.show_info;
  191. var
  192.     h:hms;
  193.     d:dms;
  194.     a:ams;
  195. begin
  196.     with current_object do
  197.         begin
  198.             right_ascension_str(h);
  199.             with h do
  200.                 begin
  201.                     ra_hours_edit.text:=inttostr(hours);
  202.                     ra_minutes_edit.text:=inttostr(minutes);
  203.                     ra_seconds_edit.text:=inttostr(seconds);
  204.                 end;
  205.             declination_str(d);
  206.             with d do
  207.                 begin
  208.                     dec_degrees_edit.text:=inttostr(degrees);
  209.                     dec_minutes_edit.text:=inttostr(minutes);
  210.                     dec_seconds_edit.text:=inttostr(seconds);
  211.                 end;
  212.             azimuth_str(d);
  213.             with d do
  214.                 begin
  215.                     az_degrees_edit.text:=inttostr(degrees);
  216.                     az_minutes_edit.text:=inttostr(minutes);
  217.                     az_seconds_edit.text:=inttostr(seconds);
  218.                 end;
  219.             altitude_str(a);
  220.             with a do
  221.                 begin
  222.                     alt_degrees_edit.text:=inttostr(degrees);
  223.                     if (degrees<0) or (degrees>90) then
  224.                         begin
  225.                             scope_control.stop_scope;
  226.                             alt_degrees_edit.Color:=clRed
  227.                         end
  228.                     else
  229.                         alt_degrees_edit.Color:=clWindow;
  230.                     alt_minutes_edit.text:=inttostr(minutes);
  231.                     alt_seconds_edit.text:=inttostr(seconds);
  232.                 end;
  233.         end;
  234.     with info_label do
  235.         begin
  236.             caption:=info_string;
  237.             width:=240;
  238.         end;
  239. end;
  240.  
  241. procedure tscope_info.get_info;
  242. var
  243.     s:string;
  244. begin
  245.     with scope_network,scope_control,scope_focus,scope_tracking do
  246.          if (send_request_check('get_info')=[exit_ok]) and
  247.                 get_string('name',s) and
  248.                 get_boolean('can_goto',can_goto) and
  249.                 get_boolean('can_sync',can_sync) and
  250.                 get_boolean('can_slew',can_slew) and
  251.                 get_boolean('can_focus',can_focus) and
  252.                 ((can_focus and get_integer('focus_speeds',focus_speeds)) or
  253.                  not can_focus) and
  254.                 get_boolean('can_track',can_track) then
  255.         begin
  256.             name:=shortstring(s);
  257.             scope_name:=name;
  258.         end
  259.     else
  260.         begin
  261.             name:='';
  262.             scope_name:='unknown scope';
  263.         end;
  264. end;
  265.  
  266. procedure tscope_info.get_ra_dec;
  267. begin
  268.     with scope_network,scope_control,scope_focus,current_object do
  269.          if (send_request_check('get_ra_dec')=[exit_ok]) and
  270.                  get_float('ra',ra) then
  271.         get_float('dec',dec);
  272. end;
  273.  
  274. procedure tscope_info.get_az_alt;
  275. begin
  276.     with scope_network,scope_control,scope_focus,current_object do
  277.          if (send_request_check('get_az_alt')=[exit_ok]) and
  278.                  get_float('alt',alt) then
  279.         get_float('az',az);
  280. end;
  281.  
  282.     { -------------
  283.         configuration
  284.         ------------- }
  285.  
  286. procedure tscope_info.load_settings;
  287. begin
  288.     ini_file:=tinifile.create(application_path+'client.ini');
  289.     with ini_file do
  290.         begin
  291.             refresh_rate:=readinteger('info','refresh_rate',default_refresh_rate);
  292.             { form }
  293.             scope.get_dimensions(scope_info,@dimensions,'info',ini_file);
  294.             left:=dimensions.form_left;
  295.             top:=dimensions.form_top;
  296.             visible:=readbool('info','visible',false);
  297.         end;
  298.     ini_file.free;
  299. end;
  300.  
  301. procedure tscope_info.save_settings;
  302. begin
  303.     ini_file.writeinteger('info','refresh_rate',refresh_rate);
  304.     { form }
  305.     scope.find_vdu(scope_info,@dimensions);
  306.     scope.write_dimensions(@dimensions,left,top,'info',ini_file);
  307.     ini_file.writebool('info','visible',visible);
  308. end;
  309.  
  310.     { ------
  311.         events
  312.         ------ }
  313.  
  314. procedure Tscope_info.FormShow(
  315.     Sender: TObject);
  316. begin
  317.     with dimensions do
  318.         begin
  319.             top:=form_top;
  320.             left:=form_left;
  321.         end;
  322. end;
  323.  
  324. procedure tscope_info.adjust;
  325. begin
  326.     with dimensions do
  327.         begin
  328.             form_top:=trunc(form_top/last_screen_height*current_height);
  329.             form_left:=trunc(form_left/last_screen_width*current_width);
  330.         end;
  331.     if visible then
  332.         show;
  333. end;
  334.  
  335. procedure tscope_info.check_visible_and_show_hide(
  336.     sender:tobject);
  337. begin
  338.     if visible then
  339.         hide_form
  340.     else
  341.         show_form;
  342.     scope.show_hide(sender,visible);
  343. end;
  344.  
  345. procedure tscope_info.hide_form;
  346. begin
  347.     with dimensions do
  348.         begin
  349.             form_top:=top;
  350.             form_left:=left;
  351.         end;
  352.     Visible:=false;
  353. end;
  354.  
  355. procedure tscope_info.show_form;
  356. begin
  357.     Visible:=true;
  358. end;
  359.  
  360. procedure Tscope_info.check_activate(
  361.     Sender: TObject);
  362. begin
  363.     scope.form_activate(scope_info,@dimensions);
  364. end;
  365.  
  366. procedure Tscope_info.refresh_rate_editChange(
  367.     Sender: TObject);
  368. begin
  369.     refresh_rate:=strtointdef(refresh_rate_edit.text,0);
  370.     if refresh_rate<5000 then
  371.         begin
  372.             refresh_rate:=5000;
  373.             refresh_rate_edit.text:=inttostr(refresh_rate);
  374.         end;
  375. end;
  376.  
  377. procedure Tscope_info.get_ra_dec_buttonClick(
  378.     Sender: TObject);
  379. begin
  380.     get_ra_dec;
  381.     show_info;
  382. end;
  383.  
  384. procedure Tscope_info.get_alt_az_buttonClick(
  385.     Sender: TObject);
  386. begin
  387.     get_az_alt;
  388.     show_info;
  389. end;
  390.  
  391. procedure Tscope_info.get_all_buttonClick(
  392.     Sender: TObject);
  393. begin
  394.     get_ra_dec;
  395.     get_az_alt;
  396.     show_info;
  397. end;
  398.  
  399. procedure Tscope_info.timer_buttonClick(
  400.     Sender: TObject);
  401. begin
  402.     if controller_timer.enabled then
  403.         begin
  404.             controller_timer.Enabled:=false;
  405.             timer_button.caption:='Start';
  406.         end
  407.     else
  408.         begin
  409.             timer_button.caption:='Stop';
  410.             controller_timer.Interval:=refresh_rate;
  411.             controller_timer.enabled:=true;
  412.         end;
  413. end;
  414.  
  415. procedure Tscope_info.controller_timerTimer(
  416.     Sender: TObject);
  417. begin
  418.     if scope_network.scope_client.connected and
  419.          not scope_network.network_timer.enabled then
  420.         begin
  421.             get_info;
  422.             show_info;
  423.         end;
  424. end;
  425.  
  426. end.
  427.